﻿using System;
using System.Data;
using System.Data.OleDb;
using System.Data.OracleClient;
using System.Data.SqlClient;
using System.Reflection;

namespace ZhiAo.BaseFramework.DBConnection
{

    public class DataReader : IDataReader, IDisposable, IDataRecord
    {
        private IDbConnection _conn;
        private IDataReader _reader;

        public DataReader(OleDbDataReader reader, OleDbConnection conn)
        {
            if (reader == null)
            {
                throw new Exception("reader is null!");
            }
            this._reader = reader;
            this._conn = conn;
        }

        public DataReader(OracleDataReader reader, OracleConnection conn)
        {
            if (reader == null)
            {
                throw new Exception("reader is null!");
            }
            this._reader = reader;
            this._conn = conn;
        }

        public DataReader(SqlDataReader reader, SqlConnection conn)
        {
            if (reader == null)
            {
                throw new Exception("reader is null!");
            }
            this._reader = reader;
            this._conn = conn;
        }

        public void Close()
        {
            this._reader.Close();
            this._conn.Close();
        }

        public void Dispose()
        {
        }

        public bool GetBoolean(int i)
        {
            if (this._reader.IsDBNull(i))
            {
                return false;
            }
            return this._reader.GetBoolean(i);
        }

        public byte GetByte(int i)
        {
            if (this._reader.IsDBNull(i))
            {
                return 0;
            }
            return this._reader.GetByte(i);
        }

        public long GetBytes(int i, long dataIndex, byte[] buffer, int bufferIndex, int length)
        {
            return this._reader.GetBytes(i, dataIndex, buffer, bufferIndex, length);
        }

        public char GetChar(int i)
        {
            if (this._reader.IsDBNull(i))
            {
                return ' ';
            }
            return this._reader.GetChar(i);
        }

        public long GetChars(int i, long dataIndex, char[] buffer, int bufferIndex, int length)
        {
            return this._reader.GetChars(i, dataIndex, buffer, bufferIndex, length);
        }

        public IDataReader GetData(int i)
        {
            return this._reader.GetData(i);
        }

        public string GetDataTypeName(int i)
        {
            return this._reader.GetDataTypeName(i);
        }

        public DateTime GetDateTime(int i)
        {
            return this._reader.GetDateTime(i);
        }

        public decimal GetDecimal(int i)
        {
            if (this._reader.IsDBNull(i))
            {
                return 0M;
            }
            return this._reader.GetDecimal(i);
        }

        public double GetDouble(int i)
        {
            if (this._reader.IsDBNull(i))
            {
                return 0.0;
            }
            return this._reader.GetDouble(i);
        }

        public Type GetFieldType(int i)
        {
            return this._reader.GetFieldType(i);
        }

        public float GetFloat(int i)
        {
            if (this._reader.IsDBNull(i))
            {
                return 0f;
            }
            return this._reader.GetFloat(i);
        }

        public Guid GetGuid(int i)
        {
            return this._reader.GetGuid(i);
        }

        public short GetInt16(int i)
        {
            if (this._reader.IsDBNull(i))
            {
                return 0;
            }
            return this._reader.GetInt16(i);
        }

        public int GetInt32(int i)
        {
            if (this._reader.IsDBNull(i))
            {
                return 0;
            }
            return this._reader.GetInt32(i);
        }

        public long GetInt64(int i)
        {
            if (this._reader.IsDBNull(i))
            {
                return 0L;
            }
            return this._reader.GetInt64(i);
        }

        public string GetName(int i)
        {
            return this._reader.GetName(i);
        }

        public int GetOrdinal(string name)
        {
            return this._reader.GetOrdinal(name);
        }

        public DataTable GetSchemaTable()
        {
            return this._reader.GetSchemaTable();
        }

        public string GetString(int i)
        {
            if (this._reader.IsDBNull(i))
            {
                return "";
            }
            return this._reader.GetString(i);
        }

        public object GetValue(int i)
        {
            return this._reader.GetValue(i);
        }

        public int GetValues(object[] values)
        {
            return this._reader.GetValues(values);
        }

        public bool IsDBNull(int i)
        {
            return this._reader.IsDBNull(i);
        }

        public bool NextResult()
        {
            return this._reader.NextResult();
        }

        public bool Read()
        {
            return this._reader.Read();
        }

        public int Depth
        {
            get
            {
                return this._reader.Depth;
            }
        }

        public int FieldCount
        {
            get
            {
                return this._reader.FieldCount;
            }
        }

        public bool IsClosed
        {
            get
            {
                return this._reader.IsClosed;
            }
        }

        public object this[int i]
        {
            get
            {
                return this._reader[i];
            }
        }

        public object this[string name]
        {
            get
            {
                return this._reader[name];
            }
        }

        public int RecordsAffected
        {
            get
            {
                return this._reader.RecordsAffected;
            }
        }
    }
}

